package router

import (
	"example.com/myproject/project/config"
	"example.com/myproject/project/controller"
	"example.com/myproject/project/middlewares"
	"fmt"
	"github.com/gin-gonic/gin"

	"net/http"
)

// 路由组配置
func SetupRouter() *gin.Engine {
	router := gin.Default()
	router.GET("/test", func(c *gin.Context) {
		c.Redirect(http.StatusMovedPermanently, "http://www.jinxideblog.com")
	})
	group1 := router.Group("/api")
	{
		group1.POST("/auth/login", controller.Login)
		group1.POST("/auth/register", controller.Register)
		group1.GET("/showflight", controller.Showflight)
		group1.GET("/getcarousel", controller.GetCarousel) //获取轮播图
	}

	group2 := router.Group("/admin")
	{
		group2.POST("/addaircraft", controller.AddAircraft)
		group2.POST("/setflight", controller.Setflight)
		group2.GET("/getfreeaircraft", controller.GetFreeAircraft)
		group2.GET("/getfreeflight", controller.GetFreeFlight)
	}
	group3 := router.Group("/user")
	{
		group3.POST("/orderticket", controller.OrderTicket)
		group3.POST("/cancelorder", controller.CancelOrder)
	}
	router.GET("/ws", middlewares.TCPMiddleware(), func(context *gin.Context) {
		err := config.Melody.HandleRequest(context.Writer, context.Request)
		if err != nil {
			fmt.Println(err)
		}
	})

	return router
}
